﻿using Game.Entity.Enum;
using Game.Kernel;
using Game.Utils;
using Game.Web.UI;
using System;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;
namespace Game.Web.Module.AccountManager
{
	public  partial class GameScoreLockerList : AdminPage
	{
		 
		public string Orderby
		{
			get
			{
				if (this.ViewState["Orderby"] == null)
				{
					this.ViewState["Orderby"] = "ORDER BY CollectDate DESC";
				}
				return (string)this.ViewState["Orderby"];
			}
			set
			{
				this.ViewState["Orderby"] = value;
			}
		}
		public string SearchItems
		{
			get
			{
				if (this.ViewState["SearchItems"] == null)
				{
					StringBuilder stringBuilder = new StringBuilder();
					if (this.userExt.UserID == 1 || this.userExt.RoleID == 1)
					{
						stringBuilder.Append(" WHERE 1=1 ");
					}
					else
					{
						stringBuilder.AppendFormat(" WHERE UserID IN( SELECT UserID FROM QPAccountsDB.dbo.AccountsInfo WHERE StationID IN({0}) )", base.OwnStation.TrimEnd(new char[]
						{
							','
						}));
					}
					this.ViewState["SearchItems"] = stringBuilder.ToString()+" and userid not in (SELECT UserID FROM QPAccountsDB.dbo.AccountsInfo WHERE isandroid =1)";
				}
				return (string)this.ViewState["SearchItems"];
			}
			set
			{
				this.ViewState["SearchItems"] = value;
			}
		}
		protected void anpPage_PageChanged(object sender, EventArgs e)
		{
			this.BindData();
		}
		private void BindData()
		{
			PagerSet gameScoreLockerList = this.aideTreasureFacade.GetGameScoreLockerList(this.anpPage.CurrentPageIndex, this.anpPage.PageSize, this.SearchItems, this.Orderby);
			this.anpPage.RecordCount = gameScoreLockerList.RecordCount;
			if (gameScoreLockerList.PageSet.Tables[0].Rows.Count > 0)
			{
				this.rptDataList.DataSource = gameScoreLockerList.PageSet;
				this.rptDataList.DataBind();
				this.rptDataList.Visible = true;
				this.litNoData.Visible = false;
				return;
			}
			this.rptDataList.Visible = false;
			this.litNoData.Visible = true;
		}
		protected void btnDelete_Click(object sender, EventArgs e)
		{
			base.AuthUserOperationPermission(Permission.Delete);
			string formString = GameRequest.GetFormString("cid");
			string sqlQuery = "WHERE UserID in (" + formString + ")";
			try
			{
				this.aideTreasureFacade.DeleteGameScoreLocker(sqlQuery);
				base.ShowInfo("删除成功");
				this.BindData();
			}
			catch
			{
				base.ShowError("删除失败");
			}
		}
		protected void btnQuery_Click(object sender, EventArgs e)
		{
			string text = this.txtSearch.Text.Trim();
			StringBuilder stringBuilder = new StringBuilder();
			if (this.userExt.UserID == 1 || this.userExt.RoleID == 1)
			{
				stringBuilder.Append(" WHERE 1=1 ");
			}
			else
			{
				stringBuilder.AppendFormat(" WHERE UserID IN( SELECT UserID FROM QPAccountsDB.dbo.AccountsInfo WHERE StationID IN({0}) )", base.OwnStation.TrimEnd(new char[]
				{
					','
				}));
			}
			if (!string.IsNullOrEmpty(text))
			{
				if (this.ckbIsLike.Checked)
				{
					stringBuilder.AppendFormat(" AND (UserID LIKE '%{0}%' OR EnterMachine LIKE '%{0}%' OR UserID IN(SELECT UserID FROM QPAccountsDB.dbo.AccountsInfo WHERE Accounts LIKE '%{0}%'))", text);
				}
				else
				{
					if (Game.Utils.Validate.IsPositiveInt(text))
					{
						stringBuilder.AppendFormat(" AND (EnterMachine='{0}' OR UserID='{0}' OR UserID IN(SELECT UserID FROM QPAccountsDB.dbo.AccountsInfo WHERE Accounts='{0}'))", text);
					}
					else
					{
						stringBuilder.AppendFormat(" AND (EnterMachine='{0}' OR UserID IN(SELECT UserID FROM QPAccountsDB.dbo.AccountsInfo WHERE Accounts='{0}'))", text);
					}
				}
			}
			this.ViewState["SearchItems"] = stringBuilder.ToString();
			this.BindData();
		}
		protected void btnRefresh_Click(object sender, EventArgs e)
		{
			this.ViewState["SearchItems"] = null;
			this.txtSearch.Text = "";
			this.ckbIsLike.Checked = false;
			this.BindData();
		}
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!base.IsPostBack)
			{
				if (base.IntParam > 0 && base.StrCmd.Equals("del"))
				{
					base.AuthUserOperationPermission(Permission.Delete);
					this.aideTreasureFacade.DeleteGameScoreLockerByUserID(base.IntParam);
					base.ShowInfo("删除成功");
				}
				this.BindData();
			}
		}
	}
}
